﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Client_Add : System.Web.UI.Page
{

    public int UserID
    {
        get { return Convert.ToInt32(ViewState["_ClientID"]); }
        set { ViewState["_ClientID"] = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetDrpDownValue();
            UserID = DongDong.Common.Misc.GetQueryStringAsInt("ID");
            if (UserID != 0)
            {
                GetClientInfo();
            }
        }
    }   

    public void GetClientInfo()
    {
        Client objClient = Client.Get(UserID);
        if (objClient != null)
        {
            txtUserName.Text = objClient.Username;
            txtPassWord.Text = objClient.Password;
            txtEmail.Text = objClient.Email;
           
            //txtAddress.Text = objClient.Address;
            //txtTelephone.Text = objClient.Tel;
            //txtQQ.Text = objClient.QQ;
            //drpSheng.SelectedValue = objClient.ProvienceID.ToString();
            drpQu.SelectedValue = objClient.ReginID.ToString();
            drpShi.SelectedValue = objClient.CityID.ToString();
            drpType.SelectedValue = objClient.Type.ToString();

            //txtBankName.Text = objClient.AccountName;
            //txtAccountName.Text = objClient.AccountHuMing;
            //txtAccountNo.Text = objClient.AccountNo;

            //drpSJRZ.SelectedValue = objClient.ShouJiRZ.ToString();
            //drpSMRZ.SelectedValue = objClient.ShiMingRZ.ToString();
            //drpYXRZ.SelectedValue = objClient.YouXiangRZ.ToString();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Client objClient = new Client();
        if (UserID != 0)
        {
            objClient = Client.Get(UserID);
        }
        //objClient.Username = txtUserName.Text.Trim();
        //objClient.Password = txtPassWord.Text.Trim();
        //objClient.Email = txtEmail.Text.Trim();
        //objClient.QQ = txtQQ.Text.Trim();
        //objClient.Tel = txtTelephone.Text.Trim();
        //objClient.BirthPlace = txtBirthAddress.Text.Trim();
        //objClient.ProvienceID = DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue);
        //objClient.CityID = DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue);
        //objClient.ReginID = DongDong.Common.Misc.ConvertToInt(drpQu.SelectedValue);
        //objClient.Address = txtAddress.Text.Trim();
        //objClient.Detail = txtJianJie.Text.Trim();
        //objClient.Type = DongDong.Common.Misc.ConvertToInt(drpType.SelectedValue);
        //if (fuTouXiang.HasFile)
        //{
        //    objClient.Touxiang = DongDong.Common.Misc.UploadFile(fuTouXiang, "/Resource/TouXiang/", ".jpg.jpeg.png.gif");
        //}
        //objClient.ShiMingRZ = DongDong.Common.Misc.IntToBool(DongDong.Common.Misc.ConvertToInt(drpSMRZ.SelectedValue));
        //objClient.ShouJiRZ = DongDong.Common.Misc.IntToBool(DongDong.Common.Misc.ConvertToInt(drpSJRZ.SelectedValue));
        //objClient.YouXiangRZ = DongDong.Common.Misc.IntToBool(DongDong.Common.Misc.ConvertToInt(drpYXRZ.SelectedValue));
        //objClient.FuWuTaiDu = DongDong.Common.Misc.ConvertToInt(txtFWTD.Text);
        //objClient.GongZuoSuDu = DongDong.Common.Misc.ConvertToInt(txtGZSD.Text);
        //objClient.WanChengZhiLiang = DongDong.Common.Misc.ConvertToInt(txtWCZL.Text);
        //objClient.AccountName = txtBankName.Text;
        //objClient.AccountHuMing = txtAccountName.Text;
        //objClient.AccountNo = txtAccountNo.Text;

        if (objClient != null)
        {

            objClient.Update();
            litMessage.Text = "修改成功";
        }
        else
        {
            //objClient.LoginTime = System.DateTime.Now;
            //objClient.LastLoginTime = System.DateTime.Now;
            //objClient.AddTime = System.DateTime.Now;
            //objClient.UserdJiFen = 0;
            //objClient.JiFen = 0;

            objClient.Add();
            litMessage.Text = "添加成功";
        }
    }
    protected void drpSheng_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue);
        //drpShi.DataSource = City.GetAllByCondition(ParentID, "");
        //drpShi.DataValueField = "ID";
        //drpShi.DataTextField = "Name";
        //drpShi.DataBind();
        drpShi.Items.Insert(0, new ListItem("请选择", "0"));
    }
    protected void drpShi_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue);
        //drpQu.DataSource = Area.GetAllByCondition(ParentID, "");
        //drpQu.DataValueField = "ID";
        //drpQu.DataTextField = "Name";
        //drpQu.DataBind();
        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    public void GetDrpDownValue()
    {
        //drpSheng.DataSource = Provience.GetAll();
        //drpSheng.DataValueField = "ID";
        //drpSheng.DataTextField = "Name";
        //drpSheng.DataBind();
        drpSheng.Items.Insert(0, new ListItem("请选择", "0"));

        drpSMRZ.PopulateFromEnum<Help.Select>();
        drpSMRZ.Items.Insert(0, new ListItem("请选择", "0"));

        drpYXRZ.PopulateFromEnum<Help.Select>();
        drpYXRZ.Items.Insert(0, new ListItem("请选择", "0"));

        drpSJRZ.PopulateFromEnum<Help.Select>();
        drpSJRZ.Items.Insert(0, new ListItem("请选择", "0"));


        drpType.PopulateFromEnum<Client.type>();
    }
}